import request from '@/utils/request'
import { parseStrEmpty } from "@/utils/ruoyi";

// 查询员工列表
export function listPerson(query) {
  return request({
    url: '/system/person/list',
    method: 'get',
    params: query
  })
}

// 查询员工详细
export function getPerson(personId) {
  return request({
    url: '/system/person/' + parseStrEmpty(personId),
    method: 'get'
  })
}

// 新增员工
export function addPerson(data) {
  return request({
    url: '/system/person',
    method: 'post',
    data: data
  })
}

// 修改员工
export function updatePerson(data) {
  return request({
    url: '/system/person',
    method: 'put',
    data: data
  })
}

// 删除员工
export function delPerson(personId) {
  return request({
    url: '/system/person/' + personId,
    method: 'delete'
  })
}

// 员工密码重置
export function resetPersonPwd(personId, password) {
  const data = {
    personId,
    password
  }
  return request({
    url: '/system/person/resetPwd',
    method: 'put',
    data: data
  })
}

// 员工状态修改
export function changePersonStatus(personId, status) {
  const data = {
    personId,
    status
  }
  return request({
    url: '/system/person/changeStatus',
    method: 'put',
    data: data
  })
}

// 查询员工个人信息
export function getPersonProfile() {
  return request({
    url: '/system/person/profile',
    method: 'get'
  })
}

// 修改员工个人信息
export function updatePersonProfile(data) {
  return request({
    url: '/system/person/profile',
    method: 'put',
    data: data
  })
}

// 员工密码重置
export function updatePersonPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  }
  return request({
    url: '/system/person/profile/updatePwd',
    method: 'put',
    params: data
  })
}

// 员工头像上传
export function uploadAvatar(data) {
  return request({
    url: '/system/person/profile/avatar',
    method: 'post',
    data: data
  })
}

// 查询授权角色
export function getAuthRole(personId) {
  return request({
    url: '/system/person/authRole/' + personId,
    method: 'get'
  })
}

// 保存授权角色
export function updateAuthRole(data) {
  return request({
    url: '/system/person/authRole',
    method: 'put',
    params: data
  })
}

// 员工选项
export function optionsPerson(data) {
  return request({
    url: '/system/person/options',
    method: 'post',
    data: data || {}
  })
}
